home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1406 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: hilbert.dnai.com!usenet
  2. From: Victor Bazarov <vbazarov@imsisoft.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: i = atoi(NULL);
  5. Date: Sat, 13 Jan 1996 10:05:26 -0800
  6. Organization: IMSI
  7. Message-ID: <30F7F466.F43@imsisoft.com>
  8. References: <DKwCsG.IGD@cs.openu.ac.il> <96009.103802DSEAMA41@portland.caps.maine.edu>
  9. NNTP-Posting-Host: vbazarov.imsisoft.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b4a (Win16; I)
  14.  
  15. Starduster wrote:
  16. > In article <DKwCsG.IGD@cs.openu.ac.il>, shimoco@mail.tlm.openu.ac.il (Shimon
  17. > Cohen) says:
  18. > >Hi !
  19. > >
  20. > >What ANSI C says about:
  21. > >i = atoi(NULL);
  22.  
  23. Actually, nothing specific.
  24. ------------------------------------------------------------------------------
  25. 7.10.1.2
  26.     int atoi(const char *nptr);
  27. "The atoi function converts the initial portion of the string pointed by nptr
  28. to int representation. Except for the behavior on error, it is equivalent to
  29.     (int)strtol(nptr, (char **)NULL, 10)
  30.  
  31. 7.10.1.5
  32.     long int strtol(const char *nptr, char **endptr, int base);
  33. [...]
  34.   "In other than "C" locale, additional implementation-defined subject sequence
  35. forms may be accepted.
  36.    If the subject is empty or does not have the expected form, no conversion is
  37. performed; ... If no conversion could be performed, zero is returned."
  38. ------------------------------------------------------------------------------
  39. My advice -- check the pointer for being NULL before passing to atoi().
  40.  
  41. >    One question: why does it matter? Why would you want to do such a thing?
  42. > Just curious.
  43.  
  44. I think Shimon wanted to use atoi with the argument got from another function,
  45. which returns NULL in case of empty input, errors, or the like.
  46.  
  47. >                                             -Darryl
  48.  
  49. Victor.
  50.  
  51. -- 
  52. Signature.
  53.